<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head th:replace="layui/common/commonHead :: commonHead(~{::title},~{::link},~{})">
    <title>新增资源 ADD</title>
    <link rel="stylesheet" th:href="@{/layuiadmin/modules/formSelects/formSelects-v4.css}" href="../../../../static/layuiadmin/modules/formSelects/formSelects-v4.css"/>
</head>
<body>

<div class="layui-form"  lay-filter="userAdmin" id="userAdmin" style="padding: 20px 0 0 0;">
    <div class="layui-form-item">
        <label class="layui-form-label">父资源名称</label>
        <div class="layui-input-inline">
            <input type="text" disabled th:value="${res.name}"  autocomplete="off" class="layui-input">
            <input type="hidden" name="parentId" th:value="${res.id}">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源名称</label>
        <div class="layui-input-inline">
            <input type="text" name="name" lay-verify="required" placeholder="请输入资源名称(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源类型</label>
        <div class="layui-input-block">
            <input type="radio" name="type" value="1" title="菜单" checked>
            <input type="radio" name="type" value="2" title="按钮">
            <input type="radio" name="type" value="3" title="接口">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">权限标识</label>
        <div class="layui-input-inline">
            <input type="text" name="resUrl" lay-verify="required"  placeholder="请输入资源URL(必填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">菜单URL</label>
        <div class="layui-input-inline">
            <input type="text" name="menuUrl"  placeholder="请输入菜单URL(选填)" autocomplete="off" class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">内部链接</label>
        <div class="layui-input-block">
            <input type="radio" name="classify" value="1" title="是" checked>
            <input type="radio" name="classify" value="2" title="否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">打开新窗口</label>
        <div class="layui-input-block">
            <input type="radio" name="target" value="1" title="是" checked>
            <input type="radio" name="target" value="2" title="否">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">资源状态</label>
        <div class="layui-input-block">
            <input type="radio" name="status" value="1" title="正常" checked>
            <input type="radio" name="status" value="2" title="锁定">
        </div>
    </div>
    <div class="layui-form-item">
        <div class="layui-input-block">
            <input class="layui-btn layui-btn-normal" type="button" lay-submit lay-filter="add" id="id-sys-res-add-submit" value="保存">
            <input class="layui-btn layui-btn-primary" onclick="layerClose()" type="button"  lay-filter="close" id="id-sys-user-add-" value="取消">
        </div>
    </div>
</div>

<div th:replace="layui/common/commonJs :: commonJs(~{})"></div>
<script>
    layui.use(['index', 'form', 'upload',"formSelects"], function(){
        var $ = layui.$
            ,form = layui.form
            ,formSelects = layui.formSelects;

        //监听锁定操作
        form.on('submit(add)', function(data){
            var field = data.field;
            //提交 Ajax 成功后，静态更新表格中的数据
            $.post('/sso/admin/menu/save', field, function (data, status) {
                if (data.status == 200) {
                    parent.layer.msg("新增成功");
                    var index = parent.layer.getFrameIndex(window.name); //先得到当前iframe层的索引
                    parent.layer.close(index); //再执行关闭
                    parent.layui.table.reload("menu_list_table");
                    parent.layui.treeGrid.reload("menu_list_table");
                } else {
                    parent.layer.msg("添加失败请重试");
                }
            })
        });

        formSelects.render("pResNameSelect");
        var url = '/sso/admin/role/allRoleByUserId?userId='+[[${res.id}]];
        formSelects.data('pResNameSelect', 'server', {
            url: url,
            delay: 500
        });
    });
    function layerClose() {
        layui.use(['layer' ], function() {
            var layer = layui.layer;
            var index=parent.layer.getFrameIndex(window.name);//获取当前弹出层的层级
            parent.layer.close(index);//关闭弹出层
        })
    }


</script>
</body>
</html>